Plex.Lib.JS.load('UI.Widget.Fly_Box');

Plex.UI.Widget.Fly_Window = function(settings)
{
	var self = this;
		
	this.setting = {
		closeImage: '/img/close.png',
		closeHoverImage: '/img/close_hover.png',
		title: 'Untitled',
		onclose: function(){}
	}
	
	for(i in settings)
	this.setting[i]=settings[i];
	
	this.box = new Plex.UI.Widget.Fly_Box(),
	this.element = {}
	this.init = function() 
	{
		self.element.table = new Element('table',{
			'class':'forumline',
			'border':0,
			'cellspacing':0,
			'cellpadding':0,
		}).adopt([
			self.element.headerRow = new Element('tr').adopt(
				self.element.headerCol = new Element('th',{'class':'titleBar'}).adopt(
					self.element.headerRowTable = new Element('table',{'width':'100%'}).adopt(
						self.element.headerRowTableRow = new Element('tr').adopt([
							self.element.headerRowTableLeftCol = new Element('td',{'width':'15%'}),
							self.element.headerRowTableMiddleCol = new Element('td',{'width':'70%','align':'center','styles':{'font-weight':'600'}}),
							self.element.headerRowTableRightCol = new Element('td',{'width':'15%'}).adopt([
								self.element.closeImage = new Element ('img',{
									'src':self.setting.closeImage,
									'events': {
										'click':function(){
											self.close()
										},
										'mouseenter':function(){
											self.element.closeImage.src=self.setting.closeHoverImage;
										},
										'mouseleave':function(){
											self.element.closeImage.src=self.setting.closeImage;
										}
									}
								}),
								self.element.nothingLink = new Element ('a',{
									'href':'#'
								})
							]),
						])
					)
				)
			),
			
			self.element.bodyRow = new Element('tr',{'class':'row2'}).adopt(
				self.element.bodyCol = self.body = new Element('td',{
					'styles' : {
						'border-color':'#707070 rgb(0, 0, 0) rgb(0, 0, 0) rgb(112, 112, 112)',
						'border-style':'solid', 
						'border-width':'1px',						
					}
				})
			)
		])
		
		self.element.headerRowTableMiddleCol.setText(self.setting.title);
		var closePreloader = new Image();
		closePreloader.src = self.setting.closeHoverImage;
				
		self.element.table.injectInside(self.box.contentDiv);
		self.box.settings.lastWidth = self.element.table.offsetWidth;
		self.box.settings.lastHeight = self.element.table.offsetHeight;
	},
	
	this.setTitle = function(newTitle)
	{
		self.element.headerRowTableMiddleCol.setText(newTitle);
	}
	
	this.open = function(width,height)
	{
		if(width && height)
		self.box.open(width,height);
		
		else
		self.box.open();
		
		
		self.element.nothingLink.focus();
	},
	
	this.close = function(onclose)
	{
		self.box.close(onclose);
		self.setting.onclose();
	}
	
	this.init();
}